/* 将localstorage 里的token 作为 全局使用的store */

import { createSlice } from '@reduxjs/toolkit'

const tokenSlice = createSlice({
  name: 'token',
  initialState: {
    value: localStorage.getItem('token'),
  },
  reducers: {
    getToken: state => {
      state.value = localStorage.getItem('token')
    },
    setNull: state => {
      localStorage.setItem('token', '')
      state.value = ''
    },
    setValue: (state, value) => {
      localStorage.setItem('token', value.value)
      state.value = value.value
    },
  },
})
export { tokenSlice }
